<template>
  <div>
    <Form ref="formData" :model="formData" :label-width="140">
      <Card
        title="新增售价市场调研"
        :bordered="false"
        dis-hover
        class="ivu-mt i-table-no-border"
      >
        <Row type="flex">
          <Col class="marginTop10" span="8"
            >调研时间：{{ formData.createOpeTime }}</Col
          >
          <Col class="marginTop10" span="8"
            >调研部门：{{ formData.departmentName }}</Col
          >
          <Col class="marginTop10" span="8"
            >调研人：{{ formData.surveyMan }}</Col
          >
          <Col class="marginTop10" span="8"
            >调研区域：
            <Select v-model="formData.surveyArea" style="width: 180px">
              <Option
                v-for="item in areas"
                :value="item.areaCode"
                :key="item.areaName"
                >{{ item.areaName }}
              </Option>
            </Select>
          </Col>
          <Col class="marginTop10" span="6"
            >单据号：{{ formData.recordNo }}</Col
          >
          <Col class="marginTop10" span="24"
            >调研目的：
            <Input
              v-model="formData.surveyTarget"
              placeholder="请输入..."
              style="width: 400px"
            />
          </Col>
          <Col class="marginTop10" span="24"
            >调研总结：
            <Input
              v-model="formData.surveyReault"
              placeholder="请输入..."
              style="width: 400px"
            />
          </Col>
        </Row>
        <Row class="card-title" justify="end" type="flex">
          <Col span="8" style="margin: 10px">
            <Button @click="guanLianSkuBt">关联SKU</Button>
            <Button @click="guanLianJingjiaBt" style="margin-left: 20px"
              >关联竞价对象</Button
            >
            <Button
              @click="saveBasicInfo"
              type="primary"
              style="margin-left: 20px"
              >保存</Button
            >
          </Col>
        </Row>
        <Row class="format_table_wrap">
          <Table
            :columns="columns1"
            :data="baseTableData"
            width="100%"
            ref="table"
          >
            <template slot-scope="{ row, index }" slot="salePriceManager">
              <Input
                v-model="row.salePriceManager"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="cashPriceGrossRate">
              <Input
                v-model="row.cashPriceGrossRate"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="cashPriceActualRate">
              <Input
                v-model="row.cashPriceActualRate"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="salePriceGrossRate">
              <Input
                v-model="row.salePriceGrossRate"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="salePriceActualRate">
              <Input
                v-model="row.salePriceActualRate"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="cashPriceActualRate">
              <Input
                v-model="row.cashPriceActualRate"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="orderNo">
              <Input
                v-model="row.orderNo"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="surveyReaultType">
              <Select
                v-model="row.surveyReaultType"
                @on-change="atinput7(row, index)"
                style="width: 100%"
                transfer
              >
                <Option
                  v-for="item in surveyReaultTypeNameList"
                  :value="item.value"
                  :key="item.name"
                >
                  {{ item.name }}</Option
                >
              </Select>
            </template>
            <template slot-scope="{ row, index }" slot="surveyReaultDes">
              <Input
                v-model="row.surveyReaultDes"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
            <template slot-scope="{ row, index }" slot="surveyReaultNote">
              <Input
                v-model="row.surveyReaultNote"
                @on-change="onChageRow(row, index)"
                placeholder="请输入..."
              />
            </template>
          </Table>
        </Row>
      </Card>
      <!-- 分页 end  -->
      <!----------------------------关联SKU开始---------------------------------->
      <Modal
        v-model="showSKUModel"
        width="1000"
        title="关联SKU"
        @on-ok="closeModal()"
        @on-cancel=""
      >
        <Card dis-hover>
          <Row type="flex" justify="start" align="bottom">
            <Col style="margin-right: 40px">
              <span style="margin-right: 10px">商品名称</span>
              <Input
                style="width: auto"
                v-model="productName"
                placeholder="请输入商品名称"
              ></Input>
            </Col>
            <Col style="margin-right: 40px">
              <span style="margin-right: 10px">商品编码</span>
              <Input
                style="width: auto"
                v-model="spuNo"
                placeholder="请输入商品编码"
              ></Input>
            </Col>
            <Col style="padding: 10px 0">
              <Button
                type="primary"
                style="margin-right: 10px"
                @click="linkSKUBt('1')"
                >查询</Button
              >
              <Button @click="linkSKUBt('0')">清空</Button>
            </Col>
          </Row>
        </Card>
        <Card dis-hover>
          <Row>
            <Tabs @on-click="linkSKUChang" style="margin: 10px">
              <TabPane label="已关联" name="Name11">
                <Table :columns="linkSkuDataCol" border :data="yglinkSkuData">
                  <template slot-scope="{ row, index }" slot="action">
                    <Button
                      type="success"
                      size="small"
                      style="margin: 3px 0"
                      @click="linkSKUSupply(row, index, '0')"
                      >取消</Button
                    >
                  </template>
                </Table>
                <div class="ivu-mt ivu-text-center">
                  <Page
                    :total="totalNum"
                    show-total
                    show-sizer
                    :current.sync="nowPage"
                    @on-change="linkSKUChang(linkSKUValue)"
                    @on-page-size-change="handleChangePageSKU"
                  />
                </div>
              </TabPane>
              <TabPane label="未关联" name="Name12">
                <Table :columns="linkSkuDataCol" border :data="wglinkSkuData">
                  <template slot-scope="{ row, index }" slot="categoryState">
                    <span v-if="row.categoryState === '1'">启用</span>
                    <span v-if="row.categoryState === '2'">未启用</span>
                  </template>
                  <template slot-scope="{ row, index }" slot="action">
                    <Button
                      type="success"
                      size="small"
                      style="margin: 3px 0"
                      @click="linkSKUSupply(row, index, '1')"
                      >关联</Button
                    >
                  </template>
                </Table>
                <div class="ivu-mt ivu-text-center">
                  <Page
                    :total="totalNum"
                    show-total
                    show-sizer
                    :current.sync="nowPage"
                    @on-change="linkSKUChang(linkSKUValue)"
                    @on-page-size-change="handleChangePageSKU"
                  />
                </div>
              </TabPane>
            </Tabs>
          </Row>
        </Card>
      </Modal>
      <!----------------------------关联SKU结束---------------------------------->
      <!----------------------------关联竞价开始---------------------------------->
      <Modal
        v-model="showJingjiaModel"
        width="1000"
        title="关联竞价对象"
        @on-ok="closeJingjiaModal()"
      >
        <Card dis-hover>
          <Row type="flex" justify="start" align="bottom">
            <Col style="margin-right: 40px">
              <span style="margin-right: 10px">公司名称</span>
              <Input
                style="width: auto"
                v-model="compareTargetName"
                placeholder="请输入公司名称"
              ></Input>
            </Col>
            <Col style="margin-right: 40px">
              <span style="margin-right: 10px">联系人</span>
              <Input
                style="width: auto"
                v-model="compareMan"
                placeholder="请输入联系人"
              ></Input>
            </Col>
            <Col style="padding: 10px 0">
              <Button
                type="primary"
                style="margin-right: 10px"
                @click="linkSKUBt('1')"
                >查询</Button
              >
              <Button @click="linkSKUBt('0')">清空</Button>
            </Col>
          </Row>
        </Card>
        <Card dis-hover>
          <Row>
            <Tabs
              @on-click="linkJingjiaChang"
              value="Name12"
              style="margin: 10px"
            >
              <TabPane label="已关联" name="Name11">
                <Table :columns="linkJiaDataCol" border :data="ygjialinkData">
                  <template slot-scope="{ row, index }" slot="action">
                    <Button
                      type="success"
                      size="small"
                      style="margin: 3px 0"
                      @click="linkJiaSupply(row, index, '0')"
                      >取消</Button
                    >
                  </template>
                </Table>
                <div class="ivu-mt ivu-text-center">
                  <Page
                    :total="totalNum"
                    show-total
                    show-sizer
                    :current.sync="nowPage"
                    @on-change="linkJingjiaChang(linkJingjiaValue)"
                    @on-page-size-change="handleChangePage"
                  />
                </div>
              </TabPane>
              <TabPane label="未关联" name="Name12">
                <Table :columns="linkJiaDataCol" border :data="wgjialinkData">
                  <template slot-scope="{ row, index }" slot="categoryState">
                    <span v-if="row.categoryState === '1'">启用</span>
                    <span v-if="row.categoryState === '2'">未启用</span>
                  </template>
                  <template slot-scope="{ row, index }" slot="action">
                    <Button
                      type="success"
                      size="small"
                      style="margin: 3px 0"
                      @click="linkJiaSupply(row, index, '1')"
                      >关联</Button
                    >
                  </template>
                </Table>
                <div class="ivu-mt ivu-text-center">
                  <Page
                    :total="totalNum"
                    show-total
                    show-sizer
                    :current.sync="nowPage"
                    @on-change="linkJingjiaChang(linkJingjiaValue)"
                    @on-page-size-change="handleChangePage"
                  />
                </div>
              </TabPane>
            </Tabs>
          </Row>
        </Card>
      </Modal>
      <!----------------------------关联SKU结束---------------------------------->
    </Form>
  </div>
</template>
<script>
import { ApiRequest } from '@api/basePage';
import { getBtnsId } from '@/libs/btnsPermission';
export default {
  mixins: [],
  components: {},
  data () {
    return {
      totalNum: 0,
      pageShow: 10,
      nowPage: 1,
      baseTableData: [],
      areas: [],
      surveyReaultTypeNameList: [
        {
          value: '1',
          name: '调整进价'
        },
        {
          value: '2',
          name: '修改定价原则'
        },
        {
          value: '3',
          name: '增加比价对象'
        },
        {
          value: '4',
          name: '增加原材料'
        },
        {
          value: '5',
          name: '无需调整'
        }
      ],
      showSKUModel: false, // SKU弹框的信息
      productName: '',
      skuData: [], // 所有选择的sku,用来给接口传递.
      compareUuids: [],
      spuNo: '', // spuNo_q=EQ
      skuNoListStr: '', // skuNo 多个用逗号 已关联传
      skuNoNotInListStr: '', // skuNo 多个用逗号 未关联传
      linkSKUValue: 'Name11',
      linkJingjiaValue: 'Name12',
      linkSkuData: [],
      yglinkSkuData: [], // 已关联
      wglinkSkuData: [], // 未关联
      ygjialinkData: [],
      wgjialinkData: [],
      linkSkuDataCol: [
        {
          title: '商品名称',
          key: 'productName'
        },
        {
          title: 'sku编码',
          key: 'skuNo'
        },
        {
          title: '规格参数',
          key: 'specDetailStr'
        },
        {
          title: '品牌',
          key: 'brandName'
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          minWidth: 80
        }
      ],
      linkJiaDataCol: [
        {
          title: '公司名称',
          key: 'compareTargetName'
        },
        {
          title: '联系人',
          key: 'compareMan'
        },
        {
          title: '联系电话',
          key: 'compareTel'
        },
        {
          title: '联系地址',
          key: 'compareAddress'
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          minWidth: 80
        }
      ],
      showJingjiaModel: false, // 关联竞价
      compareMan: '',
      compareTargetName: '',
      colums2: [],
      columns1: [
        {
          title: '分类编码',
          key: 'categoryNo',
          fixed: 'left',
          minWidth: 140
        },
        {
          title: '分类名称',
          key: 'categoryName',
          minWidth: 140
        },
        {
          title: '售价管理周期',
          slot: 'salePriceManager',
          align: 'center',
          minWidth: 140
        },
        {
          title: 'SPU编码',
          key: 'spuNo',
          align: 'center',
          minWidth: 140
        },
        {
          title: 'SKU编码',
          key: 'skuNo',
          align: 'center',
          minWidth: 140
        },
        {
          title: '商品名称',
          key: 'productName',
          align: 'center',
          minWidth: 140
        },
        {
          title: '规格',
          key: 'spec',
          align: 'center',
          minWidth: 140
        },
        {
          title: '商品管理区域',
          key: 'productManagerName',
          align: 'center',
          minWidth: 140
        },
        {
          title: '主单位',
          key: 'mainUnitName',
          align: 'center',
          minWidth: 140
        },
        {
          title: '主单位价格',
          key: 'mainUnitPrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '辅单位',
          key: 'auxiliaryUnitName',
          align: 'center',
          minWidth: 140
        },
        {
          title: '辅单位价格',
          key: 'auxiliaryUnitPrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '价格组',
          key: 'priceGruopName',
          align: 'center',
          minWidth: 140
        },
        {
          title: '面价',
          key: 'facePrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '进价',
          key: 'purchasePrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '成本价',
          key: 'costPrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '现金价',
          key: 'cashPrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '标准毛利率',
          slot: 'cashPriceGrossRate',
          align: 'center',
          minWidth: 140
        },
        {
          title: '现金价实际毛利率',
          slot: 'cashPriceActualRate',
          align: 'center',
          minWidth: 140
        },
        {
          title: '售价',
          key: 'salePrice',
          align: 'center',
          minWidth: 140
        },
        {
          title: '标准毛利率',
          slot: 'salePriceGrossRate',
          align: 'center',
          minWidth: 140
        },
        {
          title: '售价实际毛利率',
          slot: 'salePriceActualRate',
          align: 'center',
          minWidth: 140
        },
        {
          title: '最近一次调价时间',
          key: 'lastChangeTime',
          align: 'center',
          minWidth: 180
        },
        {
          title: '近12月销售额',
          key: 'lastSaleMoney',
          align: 'center',
          minWidth: 200
        },
        {
          title: '近12月毛利额',
          key: 'lastSaleGrossMoney',
          align: 'center',
          minWidth: 200
        },
        {
          title: '近12月实际毛利率',
          slot: 'lastSaleActualRate',
          align: 'center',
          minWidth: 120
        },
        {
          title: '上游单号',
          slot: 'orderNo',
          align: 'center',
          minWidth: 120
        },
        {
          title: '调研总结',
          align: 'center',
          children: [
            {
              title: '调研结果选择',
              slot: 'surveyReaultType',
              align: 'center',
              width: 140
            },
            {
              title: '调研结果描述',
              slot: 'surveyReaultDes',
              align: 'center',
              width: 140
            },
            {
              title: '审核人意见',
              slot: 'surveyReaultNote',
              align: 'center',
              width: 140
            }
          ]
        }
      ],
      formData: {
        createOpeTime: '',
        departmentName: '',
        surveyMan: '',
        surveyArea: '',
        recordNo: '',
        surveyTarget: '',
        surveyReault: ''
      },
      apiObj: {
        // 已关联/未关联sku列表
        getFinishSkuList: {
          url: '/sysback/sku/list/getFinishSkuList', // 接口地址
          type: 'post' // 接口请求类型
        },
        // 已关联/未关联对象接口
        salepricerule: {
          url: '/sysback/salepricerule/baseQueryList', // 接口地址
          type: 'post' // 接口请求类型
        },
        // 关联完SKU进行回显接口
        getInfoBySkuNos: {
          url: '/sysback/salepricesurvey/getInfoBySkuNos', // 接口地址
          type: 'post' // 接口请求类型
        },
        // 保存
        saveBasicInfo: {
          url: '/sysback/salepricesurvey/addSurvey', // 接口地址
          type: 'post' // 接口请求类型
        },
        // 获取头部信息
        getTopInfo: {
          url: '/sysback/productsurvey/getTopInfo', // 接口地址
          type: 'get' // 接口请求类型
        }
      }
    };
  },
  created () {
    this.initData();
  },
  mounted () {
    // 刷新页面清除选择的供应商缓存
    window.localStorage.removeItem('selectSupplyList');
  },
  methods: {
    initData () {
      let data = {};
      // 开始请求列表
      ApiRequest(
        this.apiObj.getTopInfo.url,
        this.apiObj.getTopInfo.type,
        data,
        false
      ).then((res) => {
        if (res.retStatus === '1') {
          this.operName = res.retData.operName;
          this.formData.departmentName = res.retData.departmentName;
          this.createOpeTime = res.retData.time;
          this.areas = res.retData.areas;
        }
      });
    },
    // SKU弹框搜索/清空
    linkSKUBt (type) {
      if (type === '0') {
        this.productName = '';
        this.spuNo = '';
        this.skuNoListStr = '';
        this.skuNoNotInListStr = '';
      }
      if (type === '1') {
        this.linkSKUChang();
      }
    },
    // SKU弹框操作事件处理
    linkSKUSupply (element, index, type) {
      if (type === '1') {
        // 关联操作
        this.wglinkSkuData.splice(index, 1);
        this.yglinkSkuData.push(element);
      } else {
        this.yglinkSkuData.splice(index, 1);
        this.wglinkSkuData.push(element);
      }
    },
    // 比较弹框操作处理
    linkJiaSupply (element, index, type) {
      if (type === '1') {
        // 关联操作
        this.wgjialinkData.splice(index, 1);
        this.ygjialinkData.push(element);
      } else {
        this.ygjialinkData.splice(index, 1);
        this.wgjialinkData.push(element);
      }
    },
    // tab切换触发
    linkSKUChang (tabName) {
      let curBtnId = getBtnsId('新增');
      sessionStorage.setItem('buttonId', curBtnId);
      this.linkSKUValue = tabName;
      // 获取已关联uuid
      if (this.yglinkSkuData.length > 0) {
        this.skuData = [];
        this.yglinkSkuData.forEach((element) => {
          this.skuData.push(element.skuNo);
        });
      }
      if (tabName === 'Name11') {
        // 已关联
        if (this.skuData.length === 0) {
          // 如果没有已关联数据,就不需要查询
          return;
        }
        let searchParam = [
          {
            name: 'productName',
            value: this.productName
          },
          {
            name: 'spuNo',
            value: this.spuNo
          },
          {
            name: 'productName_q',
            value: 'Like'
          },
          {
            name: 'spuNo_q',
            value: 'EQ'
          },
          {
            name: 'skuNoListStr',
            value: this.skuData.join(',')
          }
        ];
        let data = {
          nowPage: this.nowPage,
          pageShow: this.pageShow,
          searchParam: JSON.stringify(searchParam)
        };
        // 开始请求列表
        ApiRequest(
          this.apiObj.getFinishSkuList.url,
          this.apiObj.getFinishSkuList.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.yglinkSkuData = res.retData.results;
            this.totalNum = res.retData.totalNum;
          }
        });
      } else {
        // 未关联
        let searchParam = [
          {
            name: 'productName',
            value: this.productName
          },
          {
            name: 'spuNo',
            value: this.spuNo
          },
          {
            name: 'productName_q',
            value: 'Like'
          },
          {
            name: 'spuNo_q',
            value: 'EQ'
          },
          {
            name: 'skuNoNotInListStr',
            value: this.skuData.join(',')
          }
        ];
        let data = {
          nowPage: this.nowPage,
          pageShow: this.pageShow,
          searchParam: JSON.stringify(searchParam)
        };
        // 开始请求列表
        ApiRequest(
          this.apiObj.getFinishSkuList.url,
          this.apiObj.getFinishSkuList.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.wglinkSkuData = res.retData.results;
            this.totalNum = res.retData.totalNum;
          }
        });
      }
    },
    // 竞价切换
    linkJingjiaChang (jingjiaTabName) {
      this.linkJingjiaValue = jingjiaTabName;
      this.value = jingjiaTabName;
      // 获取已关联uuid
      if (this.ygjialinkData.length > 0) {
        this.compareUuids = [];
        this.ygjialinkData.forEach((element) => {
          this.compareUuids.push(element.uuid);
        });
      }
      if (jingjiaTabName === 'Name11') {
        // 已关联
        if (this.compareUuids.length === 0) {
          // 如果没有已关联数据,就不需要查询
          return;
        }
        let searchParam = [
          {
            name: 'compareTargetName',
            value: this.compareTargetName
          },
          {
            name: 'compareMan',
            value: this.compareMan
          },
          {
            name: 'compareMan_q',
            value: 'Like'
          },
          {
            name: 'compareTargetName_q',
            value: 'Like'
          },
          {
            name: 'uuid',
            value: this.compareUuids.join(',')
          },
          {
            name: 'uuid_q',
            value: 'IN'
          }
        ];
        let data = {
          nowPage: this.nowPage,
          pageShow: this.pageShow,
          searchParam: JSON.stringify(searchParam)
        };
        // 开始请求列表
        ApiRequest(
          this.apiObj.salepricerule.url,
          this.apiObj.salepricerule.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.ygjialinkData = res.retData.results;
            this.totalNum = res.retData.totalNum;
          }
        });
      } else {
        let searchParam = [
          {
            name: 'compareTargetName',
            value: this.compareTargetName
          },
          {
            name: 'compareMan',
            value: this.compareMan
          },
          {
            name: 'compareMan_q',
            value: 'Like'
          },
          {
            name: 'compareTargetName_q',
            value: 'Like'
          },
          {
            name: 'uuid',
            value: this.compareUuids.join(',')
          },
          {
            name: 'uuid_q',
            value: 'NotIN'
          }
        ];
        let data = {
          nowPage: this.nowPage,
          pageShow: this.pageShow,
          searchParam: JSON.stringify(searchParam)
        };
        // 开始请求列表
        ApiRequest(
          this.apiObj.salepricerule.url,
          this.apiObj.salepricerule.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.wgjialinkData = res.retData.results;
            this.totalNum = res.retData.totalNum;
          }
        });
      }
    },
    // 关闭关联SKU弹框
    closeModal () {
      if (this.yglinkSkuData.length > 0) {
        this.skuData = [];
        this.yglinkSkuData.forEach((element) => {
          this.skuData.push(element.skuNo);
        });
        let data = {
          skuNos: this.skuData.join(',')
        };
        // 开始请求列表
        ApiRequest(
          this.apiObj.getInfoBySkuNos.url + '?skuNos=' + this.skuData.join(','),
          this.apiObj.getInfoBySkuNos.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.$Message.success('关联成功');
            this.baseTableData = [];
            this.baseTableData = res.retData;
          }
        });
      }
      this.showmodal1 = false;
    },
    // 关闭竞价弹框
    closeJingjiaModal () {
      if (this.ygjialinkData.length > 0) {
        let ygjialinkData = [];
        this.ygjialinkData.forEach((item) => {
          let obj = {
            ...item,
            targetName: item.compareTargetName
          };
          ygjialinkData.push(obj);
        });
        this.showJingjiaModel = false;
        this.colums2 = [];
        this.columns1 = [];
        this.baseTableData.forEach((element, index) => {
          element.detailList = ygjialinkData;
          ygjialinkData.forEach((item, index2) => {
            if (index === 0) {
              this.pushItem(
                item.brand,
                element.grade,
                item.standardRate,
                item.price,
                item.priceActualRate,
                item.salePrice,
                item.reasonable,
                item.targetName,
                index,
                index2,
                this.ygjialinkData
              );
            }
          });
        });
        this.columns1.push(
          {
            title: '分类编码',
            key: 'categoryNo',
            fixed: 'left',
            minWidth: 140
          },
          {
            title: '分类名称',
            key: 'categoryName',
            minWidth: 140
          },
          {
            title: '售价管理周期',
            slot: 'salePriceManager',
            align: 'center',
            minWidth: 140
          },
          {
            title: 'SPU编码',
            key: 'spuNo',
            align: 'center',
            minWidth: 140
          },
          {
            title: 'SKU编码',
            key: 'skuNo',
            align: 'center',
            minWidth: 140
          },
          {
            title: '商品名称',
            key: 'productName',
            align: 'center',
            minWidth: 140
          },
          {
            title: '规格',
            key: 'spec',
            align: 'center',
            minWidth: 140
          },
          {
            title: '商品管理区域',
            key: 'productManagerName',
            align: 'center',
            minWidth: 140
          },
          {
            title: '主单位',
            key: 'mainUnitName',
            align: 'center',
            minWidth: 140
          },
          {
            title: '主单位价格',
            key: 'mainUnitPrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '辅单位',
            key: 'auxiliaryUnitName',
            align: 'center',
            minWidth: 140
          },
          {
            title: '辅单位价格',
            key: 'auxiliaryUnitPrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '价格组',
            key: 'priceGruopName',
            align: 'center',
            minWidth: 140
          },
          {
            title: '面价',
            key: 'facePrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '进价',
            key: 'purchasePrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '成本价',
            key: 'costPrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '现金价',
            key: 'cashPrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '标准毛利率',
            slot: 'cashPriceGrossRate',
            align: 'center',
            minWidth: 140
          },
          {
            title: '现金价实际毛利率',
            slot: 'cashPriceActualRate',
            align: 'center',
            minWidth: 140
          },
          {
            title: '售价',
            key: 'salePrice',
            align: 'center',
            minWidth: 140
          },
          {
            title: '标准毛利率',
            slot: 'salePriceGrossRate',
            align: 'center',
            minWidth: 140
          },
          {
            title: '售价实际毛利率',
            slot: 'salePriceActualRate',
            align: 'center',
            minWidth: 140
          },
          {
            title: '最近一次调价时间',
            key: 'lastChangeTime',
            align: 'center',
            minWidth: 180
          },
          {
            title: '近12月销售额',
            key: 'lastSaleMoney',
            align: 'center',
            minWidth: 200
          },
          {
            title: '近12月毛利额',
            key: 'lastSaleGrossMoney',
            align: 'center',
            minWidth: 200
          },
          {
            title: '近12月实际毛利率',
            slot: 'lastSaleActualRate',
            align: 'center',
            minWidth: 120
          },
          {
            title: '上游单号',
            slot: 'orderNo',
            align: 'center',
            minWidth: 120
          }
        );
        this.colums2.forEach((element, index) => {
          this.columns1.push(element);
        });

        this.columns1.push({
          title: '调研总结',
          align: 'center',
          children: [
            {
              title: '调研结果选择',
              slot: 'surveyReaultType',
              align: 'center',
              width: 140
            },
            {
              title: '调研结果描述',
              slot: 'surveyReaultDes',
              align: 'center',
              width: 140
            },
            {
              title: '审核人意见',
              slot: 'surveyReaultNote',
              align: 'center',
              width: 140
            }
          ]
        });
      }
    },
    // 点击关联sku触发
    guanLianSkuBt () {
      if (this.formData.surveyArea) {
        this.showSKUModel = true;
        this.linkSKUChang(this.linkSKUValue);
      } else {
        this.$Message.error('请先选择调研区域');
      }
    },
    // 关联竞价触发
    guanLianJingjiaBt () {
      if (this.baseTableData.length > 0) {
        this.showJingjiaModel = true;
        this.linkJingjiaChang(this.linkJingjiaValue);
      } else {
        this.$Message.error('请先关联SKU');
      }
    },
    handleChangePageSKU (val) {
      this.pageShow = val;
      this.$nextTick(() => {
        this.linkSKUChang(this.linkSKUValue);
      });
    },
    handleChangePage (val) {
      this.pageShow = val;
      this.$nextTick(() => {
        this.linkJingjiaChang(this.linkJingjiaValue);
      });
    },
    // 数据赋值处理
    onChageRow (row, index) {
      this.baseTableData[index] = row;
    },
    // 生成代码
    pushItem (
      brand,
      grade,
      standardRate,
      price,
      priceActualRate,
      salePrice,
      reasonable,
      targetName,
      waiIndex,
      neiIndex,
      row
    ) {
      let brandValue = '';
      let gradeValue = '';
      let standardRateValue = '';
      let priceValue = '';
      let priceActualRateValue = '';
      let salePriceValue = '';
      let reasonableValue = '';
      this.colums2.push({
        title: targetName,
        key: targetName,
        width: 150,
        align: 'center',
        children: [
          {
            title: '品牌',
            key: brand,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: brand
                },
                on: {
                  'on-change': (event) => {
                    brandValue = event.target.value;
                    this.onChageRow1(
                      'pinpai',
                      brandValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (brandValue !== '') {
                    }
                  }
                }
              });
            }
          },
          {
            title: '档次',
            key: grade,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: grade
                },
                on: {
                  'on-change': (event) => {
                    gradeValue = event.target.value;
                    this.onChageRow1(
                      'dangci',
                      gradeValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (gradeValue !== '') {
                    }
                  }
                }
              });
            }
          },
          {
            title: '标准差率',
            key: standardRate,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: standardRate
                },
                on: {
                  'on-change': (event) => {
                    standardRateValue = event.target.value;
                    this.onChageRow1(
                      'biaozhun',
                      standardRateValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (standardRateValue !== '') {
                    }
                  }
                }
              });
            }
          },
          {
            title: '现金价',
            key: price,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: price
                },
                on: {
                  'on-change': (event) => {
                    priceValue = event.target.value;
                    this.onChageRow1(
                      'xianjin',
                      priceValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (priceActualRateValue !== '') {
                    }
                  }
                }
              });
            }
          },
          {
            title: '现金价实际差率',
            key: priceActualRate,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: priceActualRate
                },
                on: {
                  'on-change': (event) => {
                    priceActualRateValue = event.target.value;
                    this.onChageRow1(
                      'chalv',
                      priceActualRateValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (priceActualRateValue !== '') {
                    }
                  }
                }
              });
            }
          },
          {
            title: '售价(赊欠3月)',
            key: salePrice,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: salePrice
                },
                on: {
                  'on-change': (event) => {
                    salePriceValue = event.target.value;
                    this.onChageRow1(
                      'shoujia',
                      salePriceValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (salePriceValue !== '') {
                    }
                  }
                }
              });
            }
          },
          {
            title: '是否合理',
            key: reasonable,
            width: 150,
            render: (h, params) => {
              return h('Input', {
                props: {
                  value: reasonable
                },
                on: {
                  'on-change': (event) => {
                    reasonableValue = event.target.value;
                    this.onChageRow1(
                      'heli',
                      reasonableValue,
                      waiIndex,
                      neiIndex,
                      params.index,
                      row,
                      targetName
                    );
                  },
                  'on-blur': (event) => {
                    if (reasonableValue !== '') {
                    }
                  }
                }
              });
            }
          }
        ]
      });
    },
    // 数据赋值处理
    onChageRow1 (key, value, waiIndex, neiIndex, lieIndex, row, targetName) {
      if (key === 'pinpai') {
        this.baseTableData[lieIndex].detailList[neiIndex].brand = value;
      } else if (key === 'dangci') {
        this.baseTableData[lieIndex].detailList[neiIndex].grade = value;
      } else if (key === 'biaozhun') {
        this.baseTableData[lieIndex].detailList[neiIndex].standardRate = value;
      } else if (key === 'xianjin') {
        this.baseTableData[lieIndex].detailList[neiIndex].price = value;
      } else if (key === 'chalv') {
        this.baseTableData[lieIndex].detailList[neiIndex].priceActualRate =
          value;
      } else if (key === 'shoujia') {
        this.baseTableData[lieIndex].detailList[neiIndex].salePrice = value;
      } else if (key === 'heli') {
        this.baseTableData[lieIndex].detailList[neiIndex].reasonable = value;
      } else {
        this.baseTableData[lieIndex].detailList[neiIndex].targetName =
          targetName;
      }
    },
    // 保存
    saveBasicInfo () {
      let mySubmitList = {};

      if (this.formData.surveyTarget === '') {
        this.$Message.error('调研目的不能为空');
        return false;
      }
      if (this.formData.surveyReault === '') {
        this.$Message.error('调研总结不能为空');
        return false;
      }

      if (this.formData.surveyArea === '') {
        this.$Message.error('调研区域不能为空');
        return false;
      }
      mySubmitList.surveyTarget = this.formData.surveyTarget;
      mySubmitList.surveyReault = this.formData.surveyReault;
      mySubmitList.surveyArea = this.formData.surveyArea;
      mySubmitList.detailList = this.baseTableData;
      ApiRequest(
        this.apiObj.saveBasicInfo.url,
        this.apiObj.saveBasicInfo.type,
        mySubmitList,
        false
      ).then((res) => {
        if (res.retStatus === '1') {
          this.$Message.success('保存成功');
          this.isSave = true;
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.div {
  display: flex;

  > span:nth-of-type(2),
  > span:nth-of-type(3) {
    margin-left: 20px;
  }
}

.marginTop10 {
  margin: 5px 0;
}
</style>
